package com.wjcxf.guonianla.view;


import android.graphics.Color;
import android.graphics.drawable.AnimationDrawable;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.AnimationSet;
import android.view.animation.RotateAnimation;
import android.view.animation.ScaleAnimation;
import android.view.animation.TranslateAnimation;
import android.widget.AbsoluteLayout;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.wjcxf.guonianla.MainActivity;
import com.wjcxf.guonianla.R;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import com.wjcxf.guonianla.animation.AnimationPacket;
import com.wjcxf.guonianla.utils.DensityUtils;

import java.util.ArrayList;


public class MainFragment extends Fragment implements View.OnClickListener {
    
    private MainActivity activity;
//    private TextView debugTextView;
    private long startTime = 0L;
    private final static int STATE_PLAY_ANIMATION = 123;

    private final static int STATE_REFRESH_TIME = 124;
    private int row12 = 0;
    private int col12 = 0;
    private Handler mAnimationHandler = new Handler(){
        @Override
        public void handleMessage(@NonNull Message msg) {
            super.handleMessage(msg);
            switch (msg.what){
                case STATE_PLAY_ANIMATION:

                    AnimationPacket packet = (AnimationPacket)msg.obj;
                    if(packet.getImageView() != null){
                        packet.getImageView().setVisibility(View.VISIBLE);
                        packet.playAnimation(activity);
                        Log.e(TAG+"handleMessage",packet.getName());
                    }
                    break;
                case STATE_REFRESH_TIME:
//                    debugTextView.setText("debug:"+Math.abs(startTime-System.currentTimeMillis()));
                    break;
                default:
                    break;
            }
        }
    };
    private Thread animationThread;
    private final static String TAG = MainFragment.class.getSimpleName();
    private ImageView startImageView;
    private int deviceWidthDp;
    private int deviceHeightDp;
    private AbsoluteLayout absoluteLayout;


    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        activity = (MainActivity) getActivity();
        AbsoluteLayout fragmentLayout = (AbsoluteLayout)inflater.inflate(R.layout.fragment_main, container,false);
        Drawable drawable = getResources().getDrawable(R.drawable.fu01);
        Drawable transparentDrawable = getResources().getDrawable(R.drawable.boom_15);
        absoluteLayout = new AbsoluteLayout(activity);


        startImageView = new ImageView(activity);
        startImageView.setId(View.NO_ID);
        startImageView.setAdjustViewBounds(true);
        startImageView.setImageDrawable(drawable);
        startImageView.setScaleType(ImageView.ScaleType.FIT_XY);

        transparentImg = new ImageView(activity);
        transparentImg.setId(View.NO_ID);
        transparentImg.setAdjustViewBounds(true);
        transparentImg.setImageDrawable(transparentDrawable);
        transparentImg.setScaleType(ImageView.ScaleType.FIT_XY);

        //设置居中
        //1.获取设备宽高dp
        deviceWidthDp = DensityUtils.getWidthDp(activity);
        deviceHeightDp = DensityUtils.getHeightDp(activity);
        row12 = deviceHeightDp/12;
        col12 = deviceWidthDp/12;
        absoluteLayout.setLayoutParams(new FrameLayout.LayoutParams(DensityUtils.Dp2Px(activity,deviceWidthDp),DensityUtils.Dp2Px(activity,deviceHeightDp)));
        Log.e(TAG+"onCreateView",deviceWidthDp+","+deviceHeightDp);
        //2.根据百分比计算图片dp并转为px

        int startImageWidth = DensityUtils.Dp2Px(activity,row12*4);
        int startImageHeight = DensityUtils.Dp2Px(activity,row12*4);
        int startImageX = DensityUtils.Dp2Px(activity,col12*6) -startImageWidth/2;
        int startImageY = DensityUtils.Dp2Px(activity,row12*6)-startImageHeight/2;
        startImageView.setX(startImageX);
        startImageView.setY(startImageY);

        startImageView.setMaxHeight(startImageHeight);
        startImageView.setMaxWidth(startImageWidth);
        startImageView.setVisibility(View.VISIBLE);
        startImageView.setOnClickListener(this);
        startImageView.setTag("startImageView");
        absoluteLayout.addView(startImageView);

        //放右上
        transparentImg.setX(DensityUtils.Dp2Px(activity,deviceWidthDp)-150) ;
        transparentImg.setY(0);
        transparentImg.setMaxHeight(150);
        transparentImg.setMaxWidth(150);
        transparentImg.setVisibility(View.VISIBLE);
        transparentImg.setTag("restartImageView");
        transparentImg.setOnClickListener(this);
        absoluteLayout.addView(transparentImg);

//        debugTextView = new TextView(activity);
//        debugTextView.setText("debug:");
//        debugTextView.setTextSize(18f);
//        debugTextView.setTextColor(Color.RED);
//        debugTextView.setX(100);
//        debugTextView.setY(100);
//        debugTextView.setVisibility(View.VISIBLE);
//        absoluteLayout.addView(debugTextView);
        fragmentLayout.addView(absoluteLayout);
        addAnimations();
        return fragmentLayout;
    }
    private void addAnimations(){
        addFuAnimation();
        addBaozhuAnimation(3*row12,row12);

        addDenglongAnimation();
        addBaozhuAnimation(3*row12,row12);

        addScaleFuAnimation();
        addBaozhuAnimation(3*row12,row12);

        addRotateFuAnimation();
    }

    @Override
    public void onDestroy() {
        if(animationThread != null){
            animationThread.interrupt();
        }
        super.onDestroy();
    }

    //动画需要的组件
    private ArrayList<AnimationPacket> animationList = new ArrayList<>();

    private ImageView leftFuImg;
    private ImageView centerFuImg;
    private ImageView copyCenterFuImg;
    private ImageView rightFuImg;
    private ImageView denglongImg;
    private ImageView denglongImg2;
    private ImageView transparentImg;
    //你问我为什么要申请这么多成员变量？因为鞭炮有四组同时出现 同时播放
    private ImageView[] yichuanBaozhuImages0 = new ImageView[8];
    private ImageView[] yichuanBaozhuImages1 = new ImageView[8];
    private ImageView[] yichuanBaozhuImages2 = new ImageView[8];
    private ImageView[] yichuanBaozhuImages3 = new ImageView[8];
    private int currentIndex = 0;

    private int getRandom(int max,int min){
        if(max <= min){
            return max;
        }
        //random -> [0,1)
        //random*(max-min) -> [0,max-min)
        //random*(max-min)+min -> [min,max)
        return(int) (Math.random()*Math.abs(max - min))+min;
    }
    private ImageView guonianhaoTv1;
    private ImageView guonianhaoTv2;

    private ImageView rotateFuImg01;
    private ImageView rotateFuImg02;
    private ImageView rotateFuImg03;
    private ImageView rotateFuImg04;
    
    private ImageView bigFuImg;

    private ImageView huanImg;
    private ImageView huanImg2;
    private ImageView xiImg;
    private ImageView xiImg2;
    private ImageView guoImg;
    private ImageView daImg;
    private ImageView nianImg;

    //旋转并移动
    private void addRotateFuAnimation(){

        Drawable bigFuDrawable = getResources().getDrawable(R.drawable.fu01);

        Drawable fuDrawable = getResources().getDrawable(R.drawable.fu_0);

        Drawable huanDrawable = getResources().getDrawable(R.drawable.huan);
        Drawable xiDrawable = getResources().getDrawable(R.drawable.xi);
        Drawable guoDrawable = getResources().getDrawable(R.drawable.guo);
        Drawable daDrawable = getResources().getDrawable(R.drawable.da);
        Drawable nianDrawable = getResources().getDrawable(R.drawable.nian);

        Drawable guonianlaDrawable = getResources().getDrawable(R.drawable.guonianla);

        final int rotateFuImageWidth2= DensityUtils.Dp2Px(activity,row12*2);
        final int rotateFuImageHeight2 = DensityUtils.Dp2Px(activity,row12*2);

        final int rotateFuImageWidth3 = DensityUtils.Dp2Px(activity,col12);
        final int rotateFuImageHeight3 = DensityUtils.Dp2Px(activity,col12);

        final int guonianlaImageWidth = DensityUtils.Dp2Px(activity,col12*2);
        final int guonianlaImageHeight = DensityUtils.Dp2Px(activity,row12*2);


        final int fontImageWidth = DensityUtils.Dp2Px(activity,row12*2);
        final int fontImageHeight = DensityUtils.Dp2Px(activity,row12*2);

        final int bigFuImageWidth = DensityUtils.Dp2Px(activity,col12*6);
        final int bigFuImageHeight = DensityUtils.Dp2Px(activity,col12*6);
        
        
        bigFuImg = new ImageView(activity);

        bigFuImg.setMaxWidth(bigFuImageWidth);
        bigFuImg.setMaxHeight(bigFuImageHeight);


        bigFuImg.setAdjustViewBounds(true);
        bigFuImg.setScaleType(ImageView.ScaleType.FIT_XY);
        bigFuImg.setImageDrawable(bigFuDrawable);

        bigFuImg.setX(DensityUtils.Dp2Px(activity, deviceWidthDp/2) - bigFuImageWidth/2);
        bigFuImg.setY(DensityUtils.Dp2Px(activity,deviceHeightDp/2) - bigFuImageHeight/2);
        bigFuImg.setVisibility(View.GONE);
        absoluteLayout.addView(bigFuImg);
        
        
        //欢欢喜喜过大年
        huanImg = new ImageView(activity);
        huanImg.setMaxWidth(fontImageWidth);
        huanImg.setMaxHeight(fontImageHeight);
        huanImg.setAdjustViewBounds(true);
        huanImg.setScaleType(ImageView.ScaleType.FIT_XY);
        huanImg.setImageDrawable(huanDrawable);
        huanImg.setX(DensityUtils.Dp2Px(activity, deviceWidthDp/2) - 2*fontImageWidth);
        huanImg.setY(DensityUtils.Dp2Px(activity,deviceHeightDp/2) - 3*fontImageHeight/4);
        huanImg.setVisibility(View.GONE);
        absoluteLayout.addView(huanImg);

        huanImg2 = new ImageView(activity);
        huanImg2.setMaxWidth(fontImageWidth);
        huanImg2.setMaxHeight(fontImageHeight);
        huanImg2.setAdjustViewBounds(true);
        huanImg2.setScaleType(ImageView.ScaleType.FIT_XY);
        huanImg2.setImageDrawable(huanDrawable);
        huanImg2.setX(DensityUtils.Dp2Px(activity, deviceWidthDp/2) - fontImageWidth);
        huanImg2.setY(DensityUtils.Dp2Px(activity,deviceHeightDp/2) - 3*fontImageHeight/4);
        huanImg2.setVisibility(View.GONE);
        absoluteLayout.addView(huanImg2);

        xiImg = new ImageView(activity);
        xiImg.setMaxWidth(fontImageWidth);
        xiImg.setMaxHeight(fontImageHeight);
        xiImg.setAdjustViewBounds(true);
        xiImg.setScaleType(ImageView.ScaleType.FIT_XY);
        xiImg.setImageDrawable(xiDrawable);
        xiImg.setX(DensityUtils.Dp2Px(activity, deviceWidthDp/2) );
        xiImg.setY(DensityUtils.Dp2Px(activity,deviceHeightDp/2) - 3*fontImageHeight/4);
        xiImg.setVisibility(View.GONE);
        absoluteLayout.addView(xiImg);

        xiImg2 = new ImageView(activity);
        xiImg2.setMaxWidth(fontImageWidth);
        xiImg2.setMaxHeight(fontImageHeight);
        xiImg2.setAdjustViewBounds(true);
        xiImg2.setScaleType(ImageView.ScaleType.FIT_XY);
        xiImg2.setImageDrawable(xiDrawable);
        xiImg2.setX(DensityUtils.Dp2Px(activity, deviceWidthDp/2) + fontImageWidth);
        xiImg2.setY(DensityUtils.Dp2Px(activity,deviceHeightDp/2) - 3*fontImageHeight/4);
        xiImg2.setVisibility(View.GONE);
        absoluteLayout.addView(xiImg2);


        guoImg = new ImageView(activity);
        guoImg.setMaxWidth(fontImageWidth);
        guoImg.setMaxHeight(fontImageHeight);
        guoImg.setAdjustViewBounds(true);
        guoImg.setScaleType(ImageView.ScaleType.FIT_XY);
        guoImg.setImageDrawable(guoDrawable);
        guoImg.setX(DensityUtils.Dp2Px(activity, deviceWidthDp/2) - 3*fontImageWidth/2);
        guoImg.setY(DensityUtils.Dp2Px(activity,deviceHeightDp/2) + fontImageHeight/2);
        guoImg.setVisibility(View.GONE);
        absoluteLayout.addView(guoImg);


        daImg = new ImageView(activity);
        daImg.setMaxWidth(fontImageWidth);
        daImg.setMaxHeight(fontImageHeight);
        daImg.setAdjustViewBounds(true);
        daImg.setScaleType(ImageView.ScaleType.FIT_XY);
        daImg.setImageDrawable(daDrawable);
        daImg.setX(DensityUtils.Dp2Px(activity, deviceWidthDp/2) - fontImageWidth/2);
        daImg.setY(DensityUtils.Dp2Px(activity,deviceHeightDp/2) + fontImageHeight/2);
        daImg.setVisibility(View.GONE);
        absoluteLayout.addView(daImg);

        nianImg = new ImageView(activity);
        nianImg.setMaxWidth(fontImageWidth);
        nianImg.setMaxHeight(fontImageHeight);
        nianImg.setAdjustViewBounds(true);
        nianImg.setScaleType(ImageView.ScaleType.FIT_XY);
        nianImg.setImageDrawable(nianDrawable);
        nianImg.setX(DensityUtils.Dp2Px(activity, deviceWidthDp/2) + fontImageWidth/2);
        nianImg.setY(DensityUtils.Dp2Px(activity,deviceHeightDp/2) + fontImageHeight/2);
        nianImg.setVisibility(View.GONE);
        absoluteLayout.addView(nianImg);



        //过年好弹幕
        guonianhaoTv1 = new ImageView(activity);
        guonianhaoTv2 = new ImageView(activity);
        guonianhaoTv1.setX(DensityUtils.Dp2Px(activity,deviceWidthDp));
        guonianhaoTv1.setY(DensityUtils.Dp2Px(activity,row12*2));


        guonianhaoTv2.setX(DensityUtils.Dp2Px(activity,deviceWidthDp + row12));
        guonianhaoTv2.setY(DensityUtils.Dp2Px(activity,row12*6));


        guonianhaoTv1.setAdjustViewBounds(true);
        guonianhaoTv2.setAdjustViewBounds(true);
        guonianhaoTv1.setScaleType(ImageView.ScaleType.FIT_XY);
        guonianhaoTv2.setScaleType(ImageView.ScaleType.FIT_XY);
        guonianhaoTv1.setImageDrawable(guonianlaDrawable);
        guonianhaoTv2.setImageDrawable(guonianlaDrawable);
        guonianhaoTv1.setMaxHeight(guonianlaImageHeight);
        guonianhaoTv1.setMaxWidth(guonianlaImageWidth);

        guonianhaoTv2.setMaxHeight(guonianlaImageHeight);
        guonianhaoTv2.setMaxWidth(guonianlaImageWidth);



        guonianhaoTv1.setVisibility(View.GONE);
        guonianhaoTv2.setVisibility(View.GONE);
        absoluteLayout.addView(guonianhaoTv1);
        absoluteLayout.addView(guonianhaoTv2);


        //三个福向右
        rotateFuImg01 = new ImageView(activity);

        rotateFuImg01.setMaxWidth(rotateFuImageWidth3);
        rotateFuImg01.setMaxHeight(rotateFuImageHeight3);


        rotateFuImg01.setAdjustViewBounds(true);
        rotateFuImg01.setScaleType(ImageView.ScaleType.FIT_XY);
        rotateFuImg01.setImageDrawable(fuDrawable);

        rotateFuImg01.setX(-DensityUtils.Dp2Px(activity, row12*3));
        rotateFuImg01.setY(DensityUtils.Dp2Px(activity,col12));
        rotateFuImg01.setVisibility(View.GONE);
        absoluteLayout.addView(rotateFuImg01);

        rotateFuImg02 = new ImageView(activity);

        rotateFuImg02.setMaxWidth(rotateFuImageWidth3);
        rotateFuImg02.setMaxHeight(rotateFuImageHeight3);


        rotateFuImg02.setAdjustViewBounds(true);
        rotateFuImg02.setScaleType(ImageView.ScaleType.FIT_XY);
        rotateFuImg02.setImageDrawable(fuDrawable);

        rotateFuImg02.setX(-DensityUtils.Dp2Px(activity, row12*4));
        rotateFuImg02.setY(DensityUtils.Dp2Px(activity,col12*2));
        rotateFuImg02.setVisibility(View.GONE);
        absoluteLayout.addView(rotateFuImg02);


        rotateFuImg03 = new ImageView(activity);

        rotateFuImg03.setMaxWidth(rotateFuImageWidth3);
        rotateFuImg03.setMaxHeight(rotateFuImageHeight3);


        rotateFuImg03.setAdjustViewBounds(true);
        rotateFuImg03.setScaleType(ImageView.ScaleType.FIT_XY);
        rotateFuImg03.setImageDrawable(fuDrawable);


        rotateFuImg03.setX(-DensityUtils.Dp2Px(activity, row12*8));
        rotateFuImg03.setY(DensityUtils.Dp2Px(activity,col12));
        rotateFuImg03.setVisibility(View.GONE);
        absoluteLayout.addView(rotateFuImg03);

        rotateFuImg04 = new ImageView(activity);

        rotateFuImg04.setMaxWidth(rotateFuImageWidth2);
        rotateFuImg04.setMaxHeight(rotateFuImageHeight2);


        rotateFuImg04.setAdjustViewBounds(true);
        rotateFuImg04.setScaleType(ImageView.ScaleType.FIT_XY);
        rotateFuImg04.setImageDrawable(fuDrawable);

        rotateFuImg04.setX(DensityUtils.Dp2Px(activity, deviceWidthDp+row12));
        rotateFuImg04.setY(DensityUtils.Dp2Px(activity,col12*4));
        rotateFuImg04.setVisibility(View.GONE);
        absoluteLayout.addView(rotateFuImg04);



        int duration = 18000;
        TranslateAnimation guonianhaoTranslateAnimation = new TranslateAnimation(0,-(DensityUtils.Dp2Px(activity,this.deviceWidthDp+row12*8)),0,0);
        guonianhaoTranslateAnimation.setDuration(duration);
        guonianhaoTranslateAnimation.setInterpolator(activity, android.R.anim.linear_interpolator);
        AnimationSet guonianhaoTranslateAnimationSet = new AnimationSet(true);
        guonianhaoTranslateAnimationSet.addAnimation(guonianhaoTranslateAnimation);
        guonianhaoTranslateAnimationSet.setDuration(duration);
        guonianhaoTranslateAnimationSet.setFillAfter(true);

        TranslateAnimation translateFuAnimation = new TranslateAnimation(0,(DensityUtils.Dp2Px(activity,this.deviceWidthDp+row12*8)),0,0);
        translateFuAnimation.setDuration(duration);
        translateFuAnimation.setInterpolator(activity, android.R.anim.linear_interpolator);
        AnimationSet translateFuAnimationSet = new AnimationSet(true);
        translateFuAnimationSet.addAnimation(translateFuAnimation);
        translateFuAnimationSet.setDuration(duration);
        translateFuAnimationSet.setFillAfter(true);


        TranslateAnimation translateFuAnimation2 = new TranslateAnimation(0,-(DensityUtils.Dp2Px(activity,this.deviceWidthDp+row12*8)),0,0);
        translateFuAnimation2.setDuration(duration);
        translateFuAnimation2.setInterpolator(activity, android.R.anim.linear_interpolator);
        AnimationSet translateFuAnimationSet2 = new AnimationSet(true);
        translateFuAnimationSet2.addAnimation(translateFuAnimation2);
        translateFuAnimationSet2.setDuration(duration);
        translateFuAnimationSet2.setFillAfter(true);

        AnimationPacket guonianhaoPacket1 = new AnimationPacket(guonianhaoTv1,guonianhaoTranslateAnimationSet,duration,false,"translate_guonianla1");
        AnimationPacket guonianhaoPacket2 = new AnimationPacket(guonianhaoTv2,guonianhaoTranslateAnimationSet,duration,false,"translate_guonianla2");

        animationList.add(guonianhaoPacket1);
        animationList.add(guonianhaoPacket2);
        translateFuAnimationSet.setAnimationListener(new Animation.AnimationListener() {
            @Override
            public void onAnimationStart(Animation animation) {
                AnimationDrawable rotateFuDrawable1 = (AnimationDrawable) getResources().getDrawable(
                        R.drawable.fu_animation_list);
                AnimationDrawable rotateFuDrawable2 = (AnimationDrawable) getResources().getDrawable(
                        R.drawable.fu_animation_list);
                AnimationDrawable rotateFuDrawable3 = (AnimationDrawable) getResources().getDrawable(
                        R.drawable.fu_animation_list);
                AnimationDrawable rotateFuDrawable4 = (AnimationDrawable) getResources().getDrawable(
                        R.drawable.fu_animation_list);
                rotateFuImg01.setImageDrawable(rotateFuDrawable1);
                rotateFuDrawable1.start();
                rotateFuImg02.setImageDrawable(rotateFuDrawable2);
                rotateFuDrawable2.start();
                rotateFuImg03.setImageDrawable(rotateFuDrawable3);
                rotateFuDrawable3.start();
                rotateFuImg04.setImageDrawable(rotateFuDrawable4);
                rotateFuDrawable4.start();
            }

            @Override
            public void onAnimationEnd(Animation animation) {

            }

            @Override
            public void onAnimationRepeat(Animation animation) {

            }
        });
        AnimationPacket rotateTranslatePacket1 = new AnimationPacket(rotateFuImg01,translateFuAnimationSet,duration,false,"translate_fu_01");
        AnimationPacket rotateTranslatePacket2 = new AnimationPacket(rotateFuImg02,translateFuAnimationSet,duration,false,"translate_fu_02");
        AnimationPacket rotateTranslatePacket3 = new AnimationPacket(rotateFuImg03,translateFuAnimationSet,duration,false,"translate_fu_03");
        AnimationPacket rotateTranslatePacket4 = new AnimationPacket(rotateFuImg04,translateFuAnimationSet2,duration,false,"translate_fu_04");
        animationList.add(rotateTranslatePacket1);
        animationList.add(rotateTranslatePacket2);
        animationList.add(rotateTranslatePacket3);
        animationList.add(rotateTranslatePacket4);
        animationList.add(new AnimationPacket(7000));
        //在8s内缩放欢欢喜喜过大年
        //bigFu出现
        ScaleAnimation scaleBigFuAnimation = new ScaleAnimation(1.0f, 2f, 1.0f, 2f, Animation.RELATIVE_TO_PARENT, 0.5f, Animation.RELATIVE_TO_PARENT, 0.5f);
        scaleBigFuAnimation.setRepeatMode(0);
        scaleBigFuAnimation.setDuration(8000);
        scaleBigFuAnimation.setInterpolator(activity, android.R.anim.linear_interpolator);

        AnimationSet scaleBigFuAnimationSet = new AnimationSet(true);
        scaleBigFuAnimationSet.addAnimation(scaleBigFuAnimation);
        scaleBigFuAnimationSet.setDuration(8000);
        scaleBigFuAnimationSet.setFillAfter(true);
        scaleBigFuAnimationSet.setAnimationListener(new Animation.AnimationListener() {
            @Override
            public void onAnimationStart(Animation animation) {

            }

            @Override
            public void onAnimationEnd(Animation animation) {
//                int oldX = (int)bigFuImg.getX();
//                int oldY = (int)bigFuImg.getY();
//                int oldWidth = bigFuImg.getMaxWidth();
//                int oldHeight = bigFuImg.getMaxHeight();
//                int newWidth = oldWidth*2;
//                int newHeight = oldHeight*2;
//                //修改BigImageView尺寸
//
//                bigFuImg.getLayoutParams().width =newWidth ;
//                bigFuImg.getLayoutParams().height = newWidth;
//                bigFuImg.setX(oldX+oldWidth/2 - newWidth/2);
//                bigFuImg.setY(oldY+oldHeight/2 - newHeight/2);
//                bigFuImg.requestLayout();
            }

            @Override
            public void onAnimationRepeat(Animation animation) {

            }
        });
        AnimationPacket scaleBigFuPacket = new AnimationPacket(bigFuImg,scaleBigFuAnimationSet,duration,false,"scale_big_fu");
        animationList.add(scaleBigFuPacket);


        ScaleAnimation scaleFontAnimation = new ScaleAnimation(1.0f, 2f, 1.0f, 2f, Animation.RELATIVE_TO_PARENT, 0.5f, Animation.RELATIVE_TO_PARENT, 0.5f);
        scaleFontAnimation.setRepeatMode(Animation.REVERSE);
        scaleFontAnimation.setDuration(1000);
        scaleFontAnimation.setInterpolator(activity, android.R.anim.linear_interpolator);
        AnimationSet scaleFontAnimationSet = new AnimationSet(true);
        scaleFontAnimationSet.addAnimation(scaleFontAnimation);
        scaleFontAnimationSet.setDuration(1000);
        scaleFontAnimationSet.setRepeatCount(2);
        scaleFontAnimationSet.setFillAfter(true);
        scaleFontAnimationSet.setAnimationListener(new Animation.AnimationListener() {
            @Override
            public void onAnimationStart(Animation animation) {
                huanImg.setVisibility(View.VISIBLE);
                huanImg2.setVisibility(View.VISIBLE);
                xiImg.setVisibility(View.VISIBLE);
                xiImg2.setVisibility(View.VISIBLE);
                guoImg.setVisibility(View.VISIBLE);
                daImg.setVisibility(View.VISIBLE);
                nianImg.setVisibility(View.VISIBLE);
            }

            @Override
            public void onAnimationEnd(Animation animation) {

            }

            @Override
            public void onAnimationRepeat(Animation animation) {

            }
        });
        duration = 3000;
        AnimationPacket huanPacket = new AnimationPacket(huanImg,scaleFontAnimationSet,duration,true,"scale_huan");
        animationList.add(huanPacket);

        AnimationPacket huanPacket2 = new AnimationPacket(huanImg2,scaleFontAnimationSet,duration,true,"scale_huan");
        animationList.add(huanPacket2);

        AnimationPacket xiPacket = new AnimationPacket(xiImg,scaleFontAnimationSet,duration,true,"scale_huan");
        animationList.add(xiPacket);

        AnimationPacket xiPacket2 = new AnimationPacket(xiImg2,scaleFontAnimationSet,duration,true,"scale_huan");
        animationList.add(xiPacket2);

        AnimationPacket guoPacket = new AnimationPacket(guoImg,scaleFontAnimationSet,duration,true,"scale_huan");
        animationList.add(guoPacket);

        AnimationPacket daPacket = new AnimationPacket(daImg,scaleFontAnimationSet,duration,true,"scale_huan");
        animationList.add(daPacket);

        AnimationPacket nianPacket = new AnimationPacket(nianImg,scaleFontAnimationSet,duration,true,"scale_huan");
        animationList.add(nianPacket);


//        animationList.add(new AnimationPacket(8000));

    }

    private void addScaleFuAnimation(){
        Drawable denglongDrawable = getResources().getDrawable(R.drawable.denglong);
        final int denglongImageWidth = DensityUtils.Dp2Px(activity,3*deviceHeightDp/5);
        final int denglongImageHeight = DensityUtils.Dp2Px(activity,3*deviceHeightDp/5);
        final int denglongImageX = DensityUtils.Dp2Px(activity,deviceWidthDp);
        final int denglongImageY = DensityUtils.Dp2Px(activity,row12*6)-denglongImageHeight/2;
        denglongImg2 = new ImageView(activity);
        denglongImg2.setX(denglongImageX);
        denglongImg2.setY(denglongImageY);
        denglongImg2.setMaxHeight(denglongImageHeight);
        denglongImg2.setMaxWidth(denglongImageWidth);
        denglongImg2.setPivotX(denglongImageWidth/2);
        denglongImg2.setPivotY(denglongImageHeight/2);
        denglongImg2.setAdjustViewBounds(true);
        denglongImg2.setImageDrawable(denglongDrawable);

        denglongImg2.setVisibility(View.GONE);
        absoluteLayout.addView(denglongImg2);

        int duration = 1300;

        //从右边移动到中间
        TranslateAnimation denglongTranslateAnimation = new TranslateAnimation(0,-(DensityUtils.Dp2Px(activity,this.deviceWidthDp)/2+denglongImageWidth/2),0,0);
        denglongTranslateAnimation.setDuration(duration);
        denglongTranslateAnimation.setInterpolator(activity, android.R.anim.linear_interpolator);
        AnimationSet denglongTranslateAnimationSet = new AnimationSet(true);
        denglongTranslateAnimationSet.setDuration(duration);
        denglongTranslateAnimationSet.setFillAfter(true);
        denglongTranslateAnimationSet.addAnimation(denglongTranslateAnimation);

        denglongTranslateAnimationSet.setAnimationListener(new Animation.AnimationListener() {
            @Override
            public void onAnimationStart(Animation animation) {

            }

            @Override
            public void onAnimationEnd(Animation animation) {
                //移动至中间
                denglongImg2.setX(DensityUtils.Dp2Px(activity,col12*6)-denglongImageWidth/2);
                denglongImg2.setVisibility(View.GONE);
            }

            @Override
            public void onAnimationRepeat(Animation animation) {

            }
        });
        AnimationPacket delayPacket = new AnimationPacket(200);
        animationList.add(delayPacket);
        AnimationPacket moveDenglongPacket = new AnimationPacket(denglongImg2,denglongTranslateAnimationSet,duration,true,"right_to_Big_denglong2");
        animationList.add(moveDenglongPacket);
        //放大，再放大
        ScaleAnimation scaleCenterFuAnimation = new ScaleAnimation(1.0f, 1.5f, 1.0f, 1.5f, Animation.RELATIVE_TO_PARENT, 0.5f, Animation.RELATIVE_TO_PARENT, 0.5f);
        scaleCenterFuAnimation.setRepeatMode(0);
        scaleCenterFuAnimation.setDuration(duration);
        scaleCenterFuAnimation.setInterpolator(activity, android.R.anim.linear_interpolator);

        AnimationSet scaleCenterFuAnimationSet = new AnimationSet(true);
        scaleCenterFuAnimationSet.addAnimation(scaleCenterFuAnimation);
        scaleCenterFuAnimationSet.setDuration(duration);
        scaleCenterFuAnimationSet.setFillAfter(true);
        scaleCenterFuAnimationSet.setAnimationListener(new Animation.AnimationListener() {
            @Override
            public void onAnimationStart(Animation animation) {

            }

            @Override
            public void onAnimationEnd(Animation animation) {
//                int oldX = (int)denglongImg2.getX();
//                int oldY = (int)denglongImg2.getY();
//                int oldWidth = denglongImg2.getMaxWidth();
//                int oldHeight = denglongImg2.getMaxHeight();
//                int newWidth = (int)(oldWidth*1.5);
//                int newHeight = (int)(oldHeight*1.5);
//                //修改centerImageView尺寸
//
//                denglongImg2.getLayoutParams().width =newWidth ;
//                denglongImg2.getLayoutParams().height = newWidth;
//                denglongImg2.setX(oldX+oldWidth/2 - newWidth/2);
//                denglongImg2.setY(oldY+oldHeight/2 - newHeight/2);
//                denglongImg2.requestLayout();


            }

            @Override
            public void onAnimationRepeat(Animation animation) {

            }
        });
        animationList.add(delayPacket);
        AnimationPacket scaleDenglongPacket = new AnimationPacket(denglongImg2,scaleCenterFuAnimationSet,duration,true,"scale_center_denglong");

        animationList.add(scaleDenglongPacket);


    }
    private void addDenglongAnimation(){
        Drawable denglongDrawable = getResources().getDrawable(R.drawable.denglong);
        final int denglongImageWidth = DensityUtils.Dp2Px(activity,3*deviceHeightDp/4);
        final int denglongImageHeight = DensityUtils.Dp2Px(activity,3*deviceHeightDp/4);
        final int denglongImageX = DensityUtils.Dp2Px(activity,col12*6) -denglongImageWidth/2 - DensityUtils.Dp2Px(activity,col12*6);
        final int denglongImageY = DensityUtils.Dp2Px(activity,row12*6)-denglongImageHeight/2;
        //从左右各出现一次

        denglongImg = new ImageView(activity);
        denglongImg.setX(denglongImageX);
        denglongImg.setY(denglongImageY);
        denglongImg.setMaxHeight(denglongImageHeight);
        denglongImg.setMaxWidth(denglongImageWidth);
        denglongImg.setPivotX(denglongImageWidth/2);
        denglongImg.setPivotY(denglongImageHeight/2);
        denglongImg.setAdjustViewBounds(true);
        denglongImg.setImageDrawable(denglongDrawable);

        denglongImg.setVisibility(View.GONE);
        absoluteLayout.addView(denglongImg);
        int duration = 1510;
        TranslateAnimation denglongTranslateAnimation = new TranslateAnimation(0,DensityUtils.Dp2Px(activity,this.deviceWidthDp)-denglongImageWidth/2,0,0);
        denglongTranslateAnimation.setDuration(duration);
        denglongTranslateAnimation.setInterpolator(activity, android.R.anim.linear_interpolator);
        AnimationSet denglongTranslateAnimationSet = new AnimationSet(true);
        denglongTranslateAnimationSet.setDuration(duration);
        denglongTranslateAnimationSet.setFillAfter(true);
        denglongTranslateAnimationSet.addAnimation(denglongTranslateAnimation);


        denglongTranslateAnimationSet.setAnimationListener(new Animation.AnimationListener() {
            @Override
            public void onAnimationStart(Animation animation) {
                AnimationDrawable rotatedenglongAnimationDrawable = (AnimationDrawable) getResources().getDrawable(
                        R.drawable.denglong_animation_list);
                denglongImg.setImageDrawable(rotatedenglongAnimationDrawable);
                rotatedenglongAnimationDrawable.stop();
            }

            @Override
            public void onAnimationEnd(Animation animation) {
//                denglongImg.setX(DensityUtils.Dp2Px(activity,col12*6));
                AnimationDrawable rotatedenglongAnimationDrawable = (AnimationDrawable)denglongImg.getDrawable();
                rotatedenglongAnimationDrawable.start();
            }

            @Override
            public void onAnimationRepeat(Animation animation) {

            }
        });
        AnimationPacket delayPacket = new AnimationPacket(200);
        animationList.add(delayPacket);
        AnimationPacket moveDenglongPacket = new AnimationPacket(denglongImg,denglongTranslateAnimationSet,duration,true,"right_move_denglong");
        animationList.add(moveDenglongPacket);

        TranslateAnimation denglongTranslateAnimation2 = new TranslateAnimation(0,-(DensityUtils.Dp2Px(activity,this.deviceWidthDp)+denglongImageWidth),0,0);
        denglongTranslateAnimation2.setDuration(duration);
        denglongTranslateAnimation2.setInterpolator(activity, android.R.anim.linear_interpolator);
        AnimationSet denglongTranslateAndRotateAnimationSet = new AnimationSet(true);
        denglongTranslateAndRotateAnimationSet.setDuration(duration);
        denglongTranslateAndRotateAnimationSet.addAnimation(denglongTranslateAnimation2);
        denglongTranslateAndRotateAnimationSet.setDuration(duration);
        denglongTranslateAndRotateAnimationSet.setFillAfter(true);
        denglongTranslateAndRotateAnimationSet.setAnimationListener(new Animation.AnimationListener() {
            @Override
            public void onAnimationStart(Animation animation) {
                denglongImg.setX(DensityUtils.Dp2Px(activity,deviceWidthDp)-denglongImageWidth);

            }

            @Override
            public void onAnimationEnd(Animation animation) {
                denglongImg.setX(DensityUtils.Dp2Px(activity,deviceWidthDp));
            }

            @Override
            public void onAnimationRepeat(Animation animation) {

            }
        });
        AnimationPacket throwDenglongPacket = new AnimationPacket(denglongImg,denglongTranslateAndRotateAnimationSet,duration,true,"throw_denglong");
        animationList.add(throwDenglongPacket);

        //梅开二度
        TranslateAnimation denglongTwoTranslateAnimation = new TranslateAnimation(0,-(DensityUtils.Dp2Px(activity,this.deviceWidthDp)),0,0);
        denglongTwoTranslateAnimation.setDuration(duration);
        denglongTwoTranslateAnimation.setInterpolator(activity, android.R.anim.linear_interpolator);
        AnimationSet denglongTwoTranslateAnimationSet = new AnimationSet(true);
        denglongTwoTranslateAnimationSet.setDuration(duration);
        denglongTwoTranslateAnimationSet.setFillAfter(true);
        denglongTwoTranslateAnimationSet.addAnimation(denglongTwoTranslateAnimation);


        denglongTwoTranslateAnimationSet.setAnimationListener(new Animation.AnimationListener() {
            @Override
            public void onAnimationStart(Animation animation) {

                AnimationDrawable rotatedenglongAnimationDrawable = (AnimationDrawable) getResources().getDrawable(
                        R.drawable.denglong_animation_list);
                denglongImg.setImageDrawable(rotatedenglongAnimationDrawable);
                rotatedenglongAnimationDrawable.stop();
            }

            @Override
            public void onAnimationEnd(Animation animation) {

                AnimationDrawable rotatedenglongAnimationDrawable = (AnimationDrawable)denglongImg.getDrawable();
                rotatedenglongAnimationDrawable.start();
            }

            @Override
            public void onAnimationRepeat(Animation animation) {

            }
        });

        animationList.add(delayPacket);
        AnimationPacket moveTwoDenglongPacket = new AnimationPacket(denglongImg,denglongTwoTranslateAnimationSet,duration,true,"right_move_denglong");
        animationList.add(moveTwoDenglongPacket);

        TranslateAnimation denglongTwoTranslateAnimation2 = new TranslateAnimation(0,(DensityUtils.Dp2Px(activity,this.deviceWidthDp)+denglongImageWidth),0,0);
        denglongTwoTranslateAnimation2.setDuration(duration);
        denglongTwoTranslateAnimation2.setInterpolator(activity, android.R.anim.linear_interpolator);
        AnimationSet denglongTwoTranslateAndRotateAnimationSet = new AnimationSet(true);
        denglongTwoTranslateAndRotateAnimationSet.setDuration(duration);
        denglongTwoTranslateAndRotateAnimationSet.addAnimation(denglongTwoTranslateAnimation2);
        denglongTwoTranslateAndRotateAnimationSet.setDuration(duration);
        denglongTwoTranslateAndRotateAnimationSet.setFillAfter(true);
        denglongTwoTranslateAndRotateAnimationSet.setAnimationListener(new Animation.AnimationListener() {
            @Override
            public void onAnimationStart(Animation animation) {
                denglongImg.setX(0);

            }

            @Override
            public void onAnimationEnd(Animation animation) {
                denglongImg.setVisibility(View.GONE);
            }

            @Override
            public void onAnimationRepeat(Animation animation) {

            }
        });
        AnimationPacket throwTwoDenglongPacket = new AnimationPacket(denglongImg,denglongTwoTranslateAndRotateAnimationSet,duration,true,"throw_two_denglong");
        animationList.add(throwTwoDenglongPacket);



    }
    private void addBaozhuAnimation(int offsetDpX,int offsetDpY){
        Drawable baozhuDrawable = getResources().getDrawable(R.drawable.bianpao_01);
        Drawable baozhuDrawable2 = getResources().getDrawable(R.drawable.bianpao_02);
        final int baozhuImageWidth = DensityUtils.Dp2Px(activity,row12);
        final int baozhuImageHeight = DensityUtils.Dp2Px(activity,row12);
        final int baozhuImageX = DensityUtils.Dp2Px(activity,col12*6) -baozhuImageWidth/2;
        final int baozhuImageY = DensityUtils.Dp2Px(activity,row12*6)-baozhuImageHeight/2;
        int startImageX = baozhuImageX/4 +DensityUtils.Dp2Px(activity,offsetDpX);
        int startImageY = baozhuImageY/4 +DensityUtils.Dp2Px(activity,offsetDpY);
        for(int i=0;i<8;i++){

            yichuanBaozhuImages0[i] = new ImageView(activity);
            yichuanBaozhuImages1[i] = new ImageView(activity);
            yichuanBaozhuImages2[i] = new ImageView(activity);
            yichuanBaozhuImages3[i] = new ImageView(activity);

            yichuanBaozhuImages0[i].setPivotX(yichuanBaozhuImages0[i].getWidth()/2);
            yichuanBaozhuImages1[i].setPivotX(yichuanBaozhuImages1[i].getWidth()/2);
            yichuanBaozhuImages2[i].setPivotX(yichuanBaozhuImages2[i].getWidth()/2);
            yichuanBaozhuImages3[i].setPivotX(yichuanBaozhuImages3[i].getWidth()/2);

            yichuanBaozhuImages0[i].setPivotY(yichuanBaozhuImages0[i].getHeight()/2);
            yichuanBaozhuImages1[i].setPivotY(yichuanBaozhuImages1[i].getHeight()/2);
            yichuanBaozhuImages2[i].setPivotY(yichuanBaozhuImages2[i].getHeight()/2);
            yichuanBaozhuImages3[i].setPivotY(yichuanBaozhuImages3[i].getHeight()/2);

            yichuanBaozhuImages0[i].setScaleType(ImageView.ScaleType.FIT_XY);
            yichuanBaozhuImages1[i].setScaleType(ImageView.ScaleType.FIT_XY);
            yichuanBaozhuImages2[i].setScaleType(ImageView.ScaleType.FIT_XY);
            yichuanBaozhuImages3[i].setScaleType(ImageView.ScaleType.FIT_XY);

            yichuanBaozhuImages0[i].setMaxWidth(baozhuImageWidth);
            yichuanBaozhuImages1[i].setMaxWidth(baozhuImageWidth);
            yichuanBaozhuImages2[i].setMaxWidth(baozhuImageWidth);
            yichuanBaozhuImages3[i].setMaxWidth(baozhuImageWidth);

            yichuanBaozhuImages0[i].setMaxHeight(baozhuImageHeight);
            yichuanBaozhuImages1[i].setMaxHeight(baozhuImageHeight);
            yichuanBaozhuImages2[i].setMaxHeight(baozhuImageHeight);
            yichuanBaozhuImages3[i].setMaxHeight(baozhuImageHeight);

            yichuanBaozhuImages0[i].setAdjustViewBounds(true);
            yichuanBaozhuImages1[i].setAdjustViewBounds(true);
            yichuanBaozhuImages2[i].setAdjustViewBounds(true);
            yichuanBaozhuImages3[i].setAdjustViewBounds(true);





            yichuanBaozhuImages0[i].setId(View.NO_ID);
            yichuanBaozhuImages1[i].setId(View.NO_ID);
            yichuanBaozhuImages2[i].setId(View.NO_ID);
            yichuanBaozhuImages3[i].setId(View.NO_ID);
            if(i % 2 == 0){
                yichuanBaozhuImages0[i].setRotation(315f);
                yichuanBaozhuImages1[i].setRotation(315f);
                yichuanBaozhuImages2[i].setRotation(315f);
                yichuanBaozhuImages3[i].setRotation(315f);
                yichuanBaozhuImages0[i].setImageDrawable(baozhuDrawable);
                yichuanBaozhuImages1[i].setImageDrawable(baozhuDrawable);
                yichuanBaozhuImages2[i].setImageDrawable(baozhuDrawable);
                yichuanBaozhuImages3[i].setImageDrawable(baozhuDrawable);
            }else {
                yichuanBaozhuImages0[i].setRotation(45f);
                yichuanBaozhuImages1[i].setRotation(45f);
                yichuanBaozhuImages2[i].setRotation(45f);
                yichuanBaozhuImages3[i].setRotation(45f);
                yichuanBaozhuImages0[i].setImageDrawable(baozhuDrawable2);
                yichuanBaozhuImages1[i].setImageDrawable(baozhuDrawable2);
                yichuanBaozhuImages2[i].setImageDrawable(baozhuDrawable2);
                yichuanBaozhuImages3[i].setImageDrawable(baozhuDrawable2);
            }




            yichuanBaozhuImages0[i].setX(startImageX);
            yichuanBaozhuImages1[i].setX(startImageX);
            yichuanBaozhuImages2[i].setX(startImageX);
            yichuanBaozhuImages3[i].setX(startImageX);

            yichuanBaozhuImages0[i].setY(startImageY);
            yichuanBaozhuImages1[i].setY(startImageY);
            yichuanBaozhuImages2[i].setY(startImageY);
            yichuanBaozhuImages3[i].setY(startImageY);


            yichuanBaozhuImages0[i].setVisibility(View.GONE);
            yichuanBaozhuImages1[i].setVisibility(View.GONE);
            yichuanBaozhuImages2[i].setVisibility(View.GONE);
            yichuanBaozhuImages3[i].setVisibility(View.GONE);
            absoluteLayout.addView(yichuanBaozhuImages0[i]);
            absoluteLayout.addView(yichuanBaozhuImages1[i]);
            absoluteLayout.addView(yichuanBaozhuImages2[i]);
            absoluteLayout.addView(yichuanBaozhuImages3[i]);

        }

        for(int i=0;i<yichuanBaozhuImages0.length;i++){
            if(i%2 == 0){
                yichuanBaozhuImages0[i].setY(startImageY+baozhuImageHeight*i);
            }else {
                yichuanBaozhuImages0[i].setY(baozhuImageHeight*i);
            }
            yichuanBaozhuImages0[i].setX(startImageX);
        }
        startImageX += baozhuImageWidth*3;

        for(int i=0;i<yichuanBaozhuImages1.length;i++){
            if(i%2 == 0){
                yichuanBaozhuImages1[i].setY(startImageY+baozhuImageHeight*i);
            }else {
                yichuanBaozhuImages1[i].setY(baozhuImageHeight*i);
            }
            yichuanBaozhuImages1[i].setX(startImageX);
        }

        startImageX += baozhuImageWidth*3;
        for(int i=0;i<yichuanBaozhuImages2.length;i++){
            if(i%2 == 0){
                yichuanBaozhuImages2[i].setY(startImageY+baozhuImageHeight*i);
            }else {
                yichuanBaozhuImages2[i].setY(baozhuImageHeight*i);
            }
            yichuanBaozhuImages2[i].setX(startImageX);
        }

        startImageX += baozhuImageWidth*3;
        for(int i=0;i<yichuanBaozhuImages3.length;i++){
            if(i%2 == 0){
                yichuanBaozhuImages3[i].setY(startImageY+baozhuImageHeight*i);
            }else {
                yichuanBaozhuImages3[i].setY(baozhuImageHeight*i);
            }
            yichuanBaozhuImages3[i].setX(startImageX);
        }
        int duration = 1000;
        AnimationPacket delayPacket = new AnimationPacket(duration);



        //第四排
        TranslateAnimation triggerTranslateAnimation3 = new TranslateAnimation(0,0,0,0);
        triggerTranslateAnimation3.setDuration(duration);
        triggerTranslateAnimation3.setInterpolator(activity, android.R.anim.linear_interpolator);
        AnimationSet triggerTranslateAnimationSet3 = new AnimationSet(true);
        triggerTranslateAnimationSet3.setDuration(duration);
        triggerTranslateAnimationSet3.setFillAfter(true);
        triggerTranslateAnimationSet3.addAnimation(triggerTranslateAnimation3);
        triggerTranslateAnimationSet3.setAnimationListener(new Animation.AnimationListener() {
            @Override
            public void onAnimationStart(Animation animation) {

                Drawable baozhuDrawable = getResources().getDrawable(R.drawable.bianpao_01);
                Drawable baozhuDrawable2 = getResources().getDrawable(R.drawable.bianpao_01);
                //触发前解除隐藏
                for(int i=0;i<8;i++){
                    if(i%2 == 0){
                        yichuanBaozhuImages0[i].setImageDrawable(baozhuDrawable);
                        yichuanBaozhuImages1[i].setImageDrawable(baozhuDrawable);
                        yichuanBaozhuImages2[i].setImageDrawable(baozhuDrawable);
                        yichuanBaozhuImages3[i].setImageDrawable(baozhuDrawable);
                    }else {
                        yichuanBaozhuImages0[i].setImageDrawable(baozhuDrawable2);
                        yichuanBaozhuImages1[i].setImageDrawable(baozhuDrawable2);
                        yichuanBaozhuImages2[i].setImageDrawable(baozhuDrawable2);
                        yichuanBaozhuImages3[i].setImageDrawable(baozhuDrawable2);
                    }



                    yichuanBaozhuImages0[i].setVisibility(View.VISIBLE);
                    yichuanBaozhuImages1[i].setVisibility(View.VISIBLE);
                    yichuanBaozhuImages2[i].setVisibility(View.VISIBLE);
                    yichuanBaozhuImages3[i].setVisibility(View.VISIBLE);

                }
            }

            @Override
            public void onAnimationEnd(Animation animation) {


                //爆竹动画
                AnimationDrawable animationDrawable0 = (AnimationDrawable) getResources().getDrawable(
                        R.drawable.bianpao_animation_list);
                AnimationDrawable animationDrawable1 = (AnimationDrawable) getResources().getDrawable(
                        R.drawable.bianpao_animation_list);
                AnimationDrawable animationDrawable2 = (AnimationDrawable) getResources().getDrawable(
                        R.drawable.bianpao_animation_list);
                AnimationDrawable animationDrawable3 = (AnimationDrawable) getResources().getDrawable(
                        R.drawable.bianpao_animation_list);
                AnimationDrawable animationDrawable4 = (AnimationDrawable) getResources().getDrawable(
                        R.drawable.bianpao_animation_list);
                AnimationDrawable animationDrawable5 = (AnimationDrawable) getResources().getDrawable(
                        R.drawable.bianpao_animation_list);
                AnimationDrawable animationDrawable6 = (AnimationDrawable) getResources().getDrawable(
                        R.drawable.bianpao_animation_list);
                AnimationDrawable animationDrawable7 = (AnimationDrawable) getResources().getDrawable(
                        R.drawable.bianpao_animation_list);
                yichuanBaozhuImages0[6].setImageDrawable(animationDrawable0);
                animationDrawable0.start();
                yichuanBaozhuImages1[6].setImageDrawable(animationDrawable1);
                animationDrawable1.start();
                yichuanBaozhuImages2[6].setImageDrawable(animationDrawable2);
                animationDrawable2.start();
                yichuanBaozhuImages3[6].setImageDrawable(animationDrawable3);
                animationDrawable3.start();
                yichuanBaozhuImages0[7].setImageDrawable(animationDrawable4);
                animationDrawable4.start();
                yichuanBaozhuImages1[7].setImageDrawable(animationDrawable5);
                animationDrawable5.start();
                yichuanBaozhuImages2[7].setImageDrawable(animationDrawable6);
                animationDrawable6.start();
                yichuanBaozhuImages3[7].setImageDrawable(animationDrawable7);
                animationDrawable7.start();
            }

            @Override
            public void onAnimationRepeat(Animation animation) {

            }
        });
        AnimationPacket triggerPacket3 = new AnimationPacket(transparentImg,triggerTranslateAnimationSet3,duration,false,"test");
        animationList.add(triggerPacket3);
        animationList.add(delayPacket);


        //第三排
        TranslateAnimation triggerTranslateAnimation2 = new TranslateAnimation(0,0,0,0);
        triggerTranslateAnimation2.setDuration(duration);
        triggerTranslateAnimation2.setInterpolator(activity, android.R.anim.linear_interpolator);
        AnimationSet triggerTranslateAnimationSet2 = new AnimationSet(true);
        triggerTranslateAnimationSet2.setDuration(duration);
        triggerTranslateAnimationSet2.setFillAfter(true);
        triggerTranslateAnimationSet2.addAnimation(triggerTranslateAnimation2);
        triggerTranslateAnimationSet2.setAnimationListener(new Animation.AnimationListener() {
            @Override
            public void onAnimationStart(Animation animation) {

            }

            @Override
            public void onAnimationEnd(Animation animation) {
                //爆竹动画
                AnimationDrawable animationDrawable0 = (AnimationDrawable) getResources().getDrawable(
                        R.drawable.bianpao_animation_list);
                AnimationDrawable animationDrawable1 = (AnimationDrawable) getResources().getDrawable(
                        R.drawable.bianpao_animation_list);
                AnimationDrawable animationDrawable2 = (AnimationDrawable) getResources().getDrawable(
                        R.drawable.bianpao_animation_list);
                AnimationDrawable animationDrawable3 = (AnimationDrawable) getResources().getDrawable(
                        R.drawable.bianpao_animation_list);
                AnimationDrawable animationDrawable4 = (AnimationDrawable) getResources().getDrawable(
                        R.drawable.bianpao_animation_list);
                AnimationDrawable animationDrawable5 = (AnimationDrawable) getResources().getDrawable(
                        R.drawable.bianpao_animation_list);
                AnimationDrawable animationDrawable6 = (AnimationDrawable) getResources().getDrawable(
                        R.drawable.bianpao_animation_list);
                AnimationDrawable animationDrawable7 = (AnimationDrawable) getResources().getDrawable(
                        R.drawable.bianpao_animation_list);
                yichuanBaozhuImages0[4].setImageDrawable(animationDrawable0);
                animationDrawable0.start();
                yichuanBaozhuImages1[4].setImageDrawable(animationDrawable1);
                animationDrawable1.start();
                yichuanBaozhuImages2[4].setImageDrawable(animationDrawable2);
                animationDrawable2.start();
                yichuanBaozhuImages3[4].setImageDrawable(animationDrawable3);
                animationDrawable3.start();
                yichuanBaozhuImages0[5].setImageDrawable(animationDrawable4);
                animationDrawable4.start();
                yichuanBaozhuImages1[5].setImageDrawable(animationDrawable5);
                animationDrawable5.start();
                yichuanBaozhuImages2[5].setImageDrawable(animationDrawable6);
                animationDrawable6.start();
                yichuanBaozhuImages3[5].setImageDrawable(animationDrawable7);
                animationDrawable7.start();
            }

            @Override
            public void onAnimationRepeat(Animation animation) {

            }
        });


        AnimationPacket triggerPacket2 = new AnimationPacket(transparentImg,triggerTranslateAnimationSet2,duration,false,"test");
        animationList.add(triggerPacket2);
        animationList.add(delayPacket);





        //第二排爆炸效果

        TranslateAnimation triggerTranslateAnimation1 = new TranslateAnimation(0,0,0,0);
        triggerTranslateAnimation1.setDuration(duration);
        triggerTranslateAnimation1.setInterpolator(activity, android.R.anim.linear_interpolator);
        AnimationSet triggerTranslateAnimationSet1 = new AnimationSet(true);
        triggerTranslateAnimationSet1.setDuration(duration);
        triggerTranslateAnimationSet1.setFillAfter(true);
        triggerTranslateAnimationSet1.addAnimation(triggerTranslateAnimation1);
        triggerTranslateAnimationSet1.setAnimationListener(new Animation.AnimationListener() {
            @Override
            public void onAnimationStart(Animation animation) {

            }

            @Override
            public void onAnimationEnd(Animation animation) {
                //爆竹动画
                AnimationDrawable animationDrawable0 = (AnimationDrawable) getResources().getDrawable(
                        R.drawable.bianpao_animation_list);
                AnimationDrawable animationDrawable1 = (AnimationDrawable) getResources().getDrawable(
                        R.drawable.bianpao_animation_list);
                AnimationDrawable animationDrawable2 = (AnimationDrawable) getResources().getDrawable(
                        R.drawable.bianpao_animation_list);
                AnimationDrawable animationDrawable3 = (AnimationDrawable) getResources().getDrawable(
                        R.drawable.bianpao_animation_list);
                AnimationDrawable animationDrawable4 = (AnimationDrawable) getResources().getDrawable(
                        R.drawable.bianpao_animation_list);
                AnimationDrawable animationDrawable5 = (AnimationDrawable) getResources().getDrawable(
                        R.drawable.bianpao_animation_list);
                AnimationDrawable animationDrawable6 = (AnimationDrawable) getResources().getDrawable(
                        R.drawable.bianpao_animation_list);
                AnimationDrawable animationDrawable7 = (AnimationDrawable) getResources().getDrawable(
                        R.drawable.bianpao_animation_list);
                yichuanBaozhuImages0[2].setImageDrawable(animationDrawable0);
                animationDrawable0.start();
                yichuanBaozhuImages1[2].setImageDrawable(animationDrawable1);
                animationDrawable1.start();
                yichuanBaozhuImages2[2].setImageDrawable(animationDrawable2);
                animationDrawable2.start();
                yichuanBaozhuImages3[2].setImageDrawable(animationDrawable3);
                animationDrawable3.start();
                yichuanBaozhuImages0[3].setImageDrawable(animationDrawable4);
                animationDrawable4.start();
                yichuanBaozhuImages1[3].setImageDrawable(animationDrawable5);
                animationDrawable5.start();
                yichuanBaozhuImages2[3].setImageDrawable(animationDrawable6);
                animationDrawable6.start();
                yichuanBaozhuImages3[3].setImageDrawable(animationDrawable7);
                animationDrawable7.start();
            }

            @Override
            public void onAnimationRepeat(Animation animation) {

            }
        });
        AnimationPacket triggerPacket1 = new AnimationPacket(transparentImg,triggerTranslateAnimationSet1,duration,false,"test");
        animationList.add(triggerPacket1);
        animationList.add(delayPacket);





        //第一排爆炸效果

        TranslateAnimation triggerTranslateAnimation0 = new TranslateAnimation(0,0,0,0);
        triggerTranslateAnimation0.setDuration(duration);
        triggerTranslateAnimation0.setInterpolator(activity, android.R.anim.linear_interpolator);
        AnimationSet triggerTranslateAnimationSet0 = new AnimationSet(true);
        triggerTranslateAnimationSet0.setDuration(duration);
        triggerTranslateAnimationSet0.setFillAfter(true);
        triggerTranslateAnimationSet0.addAnimation(triggerTranslateAnimation0);
        triggerTranslateAnimationSet0.setAnimationListener(new Animation.AnimationListener() {
            @Override
            public void onAnimationStart(Animation animation) {

            }

            @Override
            public void onAnimationEnd(Animation animation) {
                //爆竹动画
                AnimationDrawable animationDrawable0 = (AnimationDrawable) getResources().getDrawable(
                        R.drawable.bianpao_animation_list);
                AnimationDrawable animationDrawable1 = (AnimationDrawable) getResources().getDrawable(
                        R.drawable.bianpao_animation_list);
                AnimationDrawable animationDrawable2 = (AnimationDrawable) getResources().getDrawable(
                        R.drawable.bianpao_animation_list);
                AnimationDrawable animationDrawable3 = (AnimationDrawable) getResources().getDrawable(
                        R.drawable.bianpao_animation_list);
                AnimationDrawable animationDrawable4 = (AnimationDrawable) getResources().getDrawable(
                        R.drawable.bianpao_animation_list);
                AnimationDrawable animationDrawable5 = (AnimationDrawable) getResources().getDrawable(
                        R.drawable.bianpao_animation_list);
                AnimationDrawable animationDrawable6 = (AnimationDrawable) getResources().getDrawable(
                        R.drawable.bianpao_animation_list);
                AnimationDrawable animationDrawable7 = (AnimationDrawable) getResources().getDrawable(
                        R.drawable.bianpao_animation_list);
                yichuanBaozhuImages0[0].setImageDrawable(animationDrawable0);
                animationDrawable0.start();
                yichuanBaozhuImages1[0].setImageDrawable(animationDrawable1);
                animationDrawable1.start();
                yichuanBaozhuImages2[0].setImageDrawable(animationDrawable2);
                animationDrawable2.start();
                yichuanBaozhuImages3[0].setImageDrawable(animationDrawable3);
                animationDrawable3.start();
                yichuanBaozhuImages0[1].setImageDrawable(animationDrawable4);
                animationDrawable4.start();
                yichuanBaozhuImages1[1].setImageDrawable(animationDrawable5);
                animationDrawable5.start();
                yichuanBaozhuImages2[1].setImageDrawable(animationDrawable6);
                animationDrawable6.start();
                yichuanBaozhuImages3[1].setImageDrawable(animationDrawable7);
                animationDrawable7.start();

            }

            @Override
            public void onAnimationRepeat(Animation animation) {

            }
        });
        AnimationPacket triggerPacket0 = new AnimationPacket(transparentImg,triggerTranslateAnimationSet0,duration,false,"test");
        animationList.add(triggerPacket0);

        animationList.add(delayPacket);
        animationList.add(delayPacket);
    }
    //初始化动画
    private void addFuAnimation(){
        if(animationList.size() > 0 ){
//            for(AnimationPacket packet:animationList){
//                absoluteLayout.removeView(packet.getImageView());
//            }
            animationList.clear();
        }
        //第一段：3个福字从中间向两边散开
        Drawable drawable = getResources().getDrawable(R.drawable.fu01);
        leftFuImg = new ImageView(activity);
        centerFuImg = new ImageView(activity);
        copyCenterFuImg = new ImageView(activity);
        rightFuImg = new ImageView(activity);
        final int startImageWidth = DensityUtils.Dp2Px(activity,row12*4);
        final int startImageHeight = DensityUtils.Dp2Px(activity,row12*4);
        final int startImageX = DensityUtils.Dp2Px(activity,col12*6) -startImageWidth/2;
        final int startImageY = DensityUtils.Dp2Px(activity,row12*6)-startImageHeight/2;

        leftFuImg.setX(startImageX);
        leftFuImg.setY(startImageY);
        leftFuImg.setMaxHeight(startImageHeight);
        leftFuImg.setMaxWidth(startImageWidth);
        leftFuImg.setAdjustViewBounds(true);
        leftFuImg.setImageDrawable(drawable);

        centerFuImg.setX(startImageX);
        centerFuImg.setY(startImageY);
        centerFuImg.setMaxHeight(startImageHeight);
        centerFuImg.setMaxWidth(startImageWidth);
        centerFuImg.setAdjustViewBounds(true);
        centerFuImg.setImageDrawable(drawable);

        copyCenterFuImg.setX(startImageX);
        copyCenterFuImg.setY(startImageY);
        copyCenterFuImg.setMaxHeight(startImageHeight);
        copyCenterFuImg.setMaxWidth(startImageWidth);
        copyCenterFuImg.setAdjustViewBounds(true);
        copyCenterFuImg.setImageDrawable(drawable);

        rightFuImg.setX(startImageX);
        rightFuImg.setY(startImageY);
        rightFuImg.setMaxHeight(startImageHeight);
        rightFuImg.setMaxWidth(startImageWidth);
        rightFuImg.setAdjustViewBounds(true);
        rightFuImg.setImageDrawable(drawable);
        leftFuImg.setId(View.NO_ID);
        centerFuImg.setId(View.NO_ID);
        copyCenterFuImg.setId(View.NO_ID);
        rightFuImg.setId(View.NO_ID);

        leftFuImg.setVisibility(View.GONE);
        centerFuImg.setVisibility(View.GONE);
        rightFuImg.setVisibility(View.GONE);
        copyCenterFuImg.setVisibility(View.GONE);
        absoluteLayout.addView(leftFuImg);
        absoluteLayout.addView(centerFuImg);
        absoluteLayout.addView(copyCenterFuImg);
        absoluteLayout.addView(rightFuImg);

        int duration = 500;
        TranslateAnimation leftFuTranslateAnimation = new TranslateAnimation(0,-startImageHeight-10,0,0);
        leftFuTranslateAnimation.setDuration(duration);

        leftFuTranslateAnimation.setInterpolator(activity, android.R.anim.linear_interpolator);
        AnimationSet leftFuTranslateAnimationSet = new AnimationSet(true);
        leftFuTranslateAnimationSet.setDuration(duration);
        leftFuTranslateAnimationSet.setFillAfter(true);
        leftFuTranslateAnimationSet.addAnimation(leftFuTranslateAnimation);


        TranslateAnimation centerFuTranslateAnimation = new TranslateAnimation(0,0,0,0);
        centerFuTranslateAnimation.setDuration(duration);
        centerFuTranslateAnimation.setInterpolator(activity, android.R.anim.linear_interpolator);
        AnimationSet centerFuTranslateAnimationSet = new AnimationSet(true);
        centerFuTranslateAnimationSet.setDuration(duration);
        centerFuTranslateAnimationSet.setFillAfter(true);
        centerFuTranslateAnimationSet.addAnimation(centerFuTranslateAnimation);

        TranslateAnimation rightFuTranslateAnimation = new TranslateAnimation(0,startImageHeight+10,0,0);
        rightFuTranslateAnimation.setDuration(duration);
        rightFuTranslateAnimation.setInterpolator(activity, android.R.anim.linear_interpolator);
        AnimationSet rightFuTranslateAnimationSet = new AnimationSet(true);
        rightFuTranslateAnimationSet.setDuration(duration);
        rightFuTranslateAnimationSet.setFillAfter(true);
        rightFuTranslateAnimationSet.addAnimation(rightFuTranslateAnimation);

        leftFuTranslateAnimationSet.setAnimationListener(new Animation.AnimationListener() {
            @Override
            public void onAnimationStart(Animation animation) {

            }

            @Override
            public void onAnimationEnd(Animation animation) {
                leftFuImg.setVisibility(View.GONE);
            }

            @Override
            public void onAnimationRepeat(Animation animation) {

            }
        });
        rightFuTranslateAnimationSet.setAnimationListener(new Animation.AnimationListener() {
            @Override
            public void onAnimationStart(Animation animation) {

            }

            @Override
            public void onAnimationEnd(Animation animation) {
                rightFuImg.setVisibility(View.GONE);
            }

            @Override
            public void onAnimationRepeat(Animation animation) {

            }
        });
        AnimationPacket leftFuPacket = new AnimationPacket(leftFuImg,leftFuTranslateAnimationSet,duration,true,"translate_left_fu");
        final AnimationPacket centerFuPacket = new AnimationPacket(centerFuImg,centerFuTranslateAnimationSet,duration,false,"translate_center_fu");
        AnimationPacket rightFuPacket = new AnimationPacket(rightFuImg,rightFuTranslateAnimationSet,duration,true,"translate_right_fu");
        animationList.add(centerFuPacket);
        animationList.add(leftFuPacket);
        animationList.add(rightFuPacket);

        //第二段 隐藏边上两个福字，并放大中间福字
        AlphaAnimation hiddenLeftFuAnimation = new AlphaAnimation(1f,0f);
        hiddenLeftFuAnimation.setDuration(duration);
        hiddenLeftFuAnimation.setInterpolator(activity, android.R.anim.linear_interpolator);
        AnimationSet hiddenLeftFuAnimationSet = new AnimationSet(true);
        hiddenLeftFuAnimationSet.addAnimation(hiddenLeftFuAnimation);
        hiddenLeftFuAnimationSet.setDuration(duration);

        hiddenLeftFuAnimationSet.setFillAfter(true);

        AlphaAnimation hiddenRightFuAnimation = new AlphaAnimation(1f,0f);
        hiddenRightFuAnimation.setDuration(duration);
        hiddenRightFuAnimation.setInterpolator(activity, android.R.anim.linear_interpolator);
        AnimationSet hiddenRightFuAnimationSet = new AnimationSet(true);
        hiddenRightFuAnimationSet.addAnimation(hiddenRightFuAnimation);
        hiddenRightFuAnimationSet.setDuration(duration);
        hiddenRightFuAnimationSet.setFillAfter(true);
//
        AnimationPacket delayPacket = new AnimationPacket(duration);
        AnimationPacket hiddenLeftFuPacket = new AnimationPacket(leftFuImg,hiddenLeftFuAnimationSet,duration,true,"hidden_left_fu");
        AnimationPacket hiddenRightFuPacket = new AnimationPacket(rightFuImg,hiddenRightFuAnimationSet,duration,false,"hidden_left_fu");

        animationList.add(hiddenLeftFuPacket);
        animationList.add(hiddenRightFuPacket);
        animationList.add(delayPacket);
        ScaleAnimation scaleCenterFuAnimation = new ScaleAnimation(1.0f, 1.8f, 1.0f, 1.8f, Animation.RELATIVE_TO_PARENT, 0.5f, Animation.RELATIVE_TO_PARENT, 0.5f);
        scaleCenterFuAnimation.setRepeatMode(0);
        scaleCenterFuAnimation.setDuration(duration);
        scaleCenterFuAnimation.setInterpolator(activity, android.R.anim.linear_interpolator);

        AnimationSet scaleCenterFuAnimationSet = new AnimationSet(true);
        scaleCenterFuAnimationSet.addAnimation(scaleCenterFuAnimation);
        scaleCenterFuAnimationSet.setDuration(duration);
        scaleCenterFuAnimationSet.setFillAfter(true);
        scaleCenterFuAnimationSet.setAnimationListener(new Animation.AnimationListener() {
            @Override
            public void onAnimationStart(Animation animation) {

            }

            @Override
            public void onAnimationEnd(Animation animation) {
                int oldX = (int)centerFuImg.getX();
                int oldY = (int)centerFuImg.getY();
                int oldWidth = centerFuImg.getMaxWidth();
                int oldHeight = centerFuImg.getMaxHeight();
                int newWidth = (int)(oldWidth*1.8);
                int newHeight = (int)(oldHeight*1.8);
                //修改centerImageView尺寸

                centerFuImg.getLayoutParams().width =newWidth ;
                centerFuImg.getLayoutParams().height = newWidth;

                centerFuImg.setX(oldX+oldWidth/2 - newWidth/2);
                centerFuImg.setY(oldY+oldHeight/2 - newHeight/2);
                centerFuImg.requestLayout();

                copyCenterFuImg.getLayoutParams().width =newWidth ;
                copyCenterFuImg.getLayoutParams().height = newWidth;

                copyCenterFuImg.setX(oldX+oldWidth/2 - newWidth/2);
                copyCenterFuImg.setY(oldY+oldHeight/2 - newHeight/2);
                copyCenterFuImg.requestLayout();

            }

            @Override
            public void onAnimationRepeat(Animation animation) {

            }
        });
        animationList.add(delayPacket);
        AnimationPacket scaleCenterFuPacket = new AnimationPacket(centerFuImg,scaleCenterFuAnimationSet,duration,true,"scale_center_fu");

        animationList.add(scaleCenterFuPacket);

        //第三段 中间的福变成两个并整体居中再变回来

        TranslateAnimation centerFuTranslateAnimation2 = new TranslateAnimation(0,-(int)(startImageWidth*1.8)/2-5,0,0);
        centerFuTranslateAnimation2.setDuration(duration);
        centerFuTranslateAnimation2.setInterpolator(activity, android.R.anim.linear_interpolator);
        AnimationSet centerFuTranslateAnimationSet2 = new AnimationSet(true);
        centerFuTranslateAnimationSet2.setDuration(duration);
        centerFuTranslateAnimationSet2.setFillAfter(true);

        centerFuTranslateAnimationSet2.addAnimation(centerFuTranslateAnimation2);
        TranslateAnimation copyCenterFuTranslateAnimation2 = new TranslateAnimation(0,(int)(startImageWidth*1.8)/2+5,0,0);
        copyCenterFuTranslateAnimation2.setDuration(duration);
        copyCenterFuTranslateAnimation2.setInterpolator(activity, android.R.anim.linear_interpolator);
        AnimationSet copyCenterFuTranslateAnimationSet2 = new AnimationSet(true);
        copyCenterFuTranslateAnimationSet2.setDuration(duration);
        copyCenterFuTranslateAnimationSet2.setFillAfter(true);
        copyCenterFuTranslateAnimationSet2.addAnimation(copyCenterFuTranslateAnimation2);

        centerFuTranslateAnimationSet2.setAnimationListener(new Animation.AnimationListener() {
            @Override
            public void onAnimationStart(Animation animation) {

            }

            @Override
            public void onAnimationEnd(Animation animation) {
                centerFuImg.clearAnimation();
            }

            @Override
            public void onAnimationRepeat(Animation animation) {

            }
        });

        copyCenterFuTranslateAnimationSet2.setAnimationListener(new Animation.AnimationListener() {
            @Override
            public void onAnimationStart(Animation animation) {

            }

            @Override
            public void onAnimationEnd(Animation animation) {
                copyCenterFuImg.clearAnimation();
                copyCenterFuImg.setVisibility(View.GONE);
            }

            @Override
            public void onAnimationRepeat(Animation animation) {

            }
        });

        AnimationPacket centerFuPacket2 = new AnimationPacket(centerFuImg,centerFuTranslateAnimationSet2,duration,false,"move_center_fu");
        AnimationPacket copyCenterFuPacket2 = new AnimationPacket(copyCenterFuImg,copyCenterFuTranslateAnimationSet2,duration,false,"move_center_fu");



        animationList.add(centerFuPacket2);
        animationList.add(copyCenterFuPacket2);
        animationList.add(delayPacket);
        animationList.add(delayPacket);
        //第四段 变成倒置的福并旋转
        RotateAnimation invertedCenterFuImgAnimation = new RotateAnimation(0, -180, Animation.RELATIVE_TO_PARENT, 0.5f, Animation.RELATIVE_TO_PARENT, 0.5f);
        invertedCenterFuImgAnimation.setDuration(duration);

        invertedCenterFuImgAnimation.setInterpolator(activity, android.R.anim.linear_interpolator);
        AnimationSet invertedCenterFuImgAnimationSet = new AnimationSet(true);
        invertedCenterFuImgAnimationSet.addAnimation(invertedCenterFuImgAnimation);
        invertedCenterFuImgAnimationSet.setDuration(duration);
        invertedCenterFuImgAnimationSet.setFillAfter(true);
        invertedCenterFuImgAnimationSet.setRepeatMode(Animation.REVERSE);
        AnimationPacket invertedCenterFuPacket = new AnimationPacket(centerFuImg,invertedCenterFuImgAnimationSet,duration,true,"inverted_center_fu");
        animationList.add(invertedCenterFuPacket);
        animationList.add(delayPacket);



        RotateAnimation rotateCenterFuImgAnimation = new RotateAnimation(0, 7200, Animation.RELATIVE_TO_PARENT, 0.5f, Animation.RELATIVE_TO_PARENT, 0.5f);
        rotateCenterFuImgAnimation.setDuration(duration*4);

        rotateCenterFuImgAnimation.setInterpolator(activity, android.R.anim.linear_interpolator);
        AnimationSet rotateCenterFuImgAnimationSet = new AnimationSet(true);
        rotateCenterFuImgAnimationSet.addAnimation(rotateCenterFuImgAnimation);
        rotateCenterFuImgAnimationSet.setDuration(duration*4);
        rotateCenterFuImgAnimationSet.setFillAfter(true);
        rotateCenterFuImgAnimationSet.setRepeatMode(Animation.REVERSE);
        AnimationPacket rotateCenterFuPacket = new AnimationPacket(centerFuImg,rotateCenterFuImgAnimationSet,duration*4,true,"rotate_center_fu");
        animationList.add(rotateCenterFuPacket);


        TranslateAnimation centerFuTranslateAnimation3 = new TranslateAnimation(0,-(int)(startImageWidth*1.8)/2-5,0,0);
        centerFuTranslateAnimation3.setDuration(duration);
        centerFuTranslateAnimation3.setInterpolator(activity, android.R.anim.linear_interpolator);
        AnimationSet centerFuTranslateAnimationSet3 = new AnimationSet(true);
        centerFuTranslateAnimationSet3.setDuration(duration);
        centerFuTranslateAnimationSet3.setFillAfter(true);

        centerFuTranslateAnimationSet3.addAnimation(centerFuTranslateAnimation2);
        TranslateAnimation copyCenterFuTranslateAnimation3 = new TranslateAnimation(0,(int)(startImageWidth*1.8)/2+5,0,0);
        copyCenterFuTranslateAnimation3.setDuration(duration);
        copyCenterFuTranslateAnimation3.setInterpolator(activity, android.R.anim.linear_interpolator);
        AnimationSet copyCenterFuTranslateAnimationSet3 = new AnimationSet(true);
        copyCenterFuTranslateAnimationSet3.setDuration(duration);
        copyCenterFuTranslateAnimationSet3.setFillAfter(true);
        copyCenterFuTranslateAnimationSet3.addAnimation(copyCenterFuTranslateAnimation2);

        centerFuTranslateAnimationSet3.setAnimationListener(new Animation.AnimationListener() {
            @Override
            public void onAnimationStart(Animation animation) {

            }

            @Override
            public void onAnimationEnd(Animation animation) {
                int oldX = (int)centerFuImg.getX();
                centerFuImg.setX(oldX+(startImageWidth*1.8f)/2+5);
                centerFuImg.setPivotX(centerFuImg.getWidth()/2);
                centerFuImg.setPivotY(centerFuImg.getHeight()/2);
                centerFuImg.setVisibility(View.GONE);
            }

            @Override
            public void onAnimationRepeat(Animation animation) {

            }
        });

        copyCenterFuTranslateAnimationSet3.setAnimationListener(new Animation.AnimationListener() {
            @Override
            public void onAnimationStart(Animation animation) {

            }

            @Override
            public void onAnimationEnd(Animation animation) {
                int oldX = (int)copyCenterFuImg.getX();
                copyCenterFuImg.setX(oldX-(startImageWidth*1.8f)/2-5);
                copyCenterFuImg.setPivotX(centerFuImg.getWidth()/2);
                copyCenterFuImg.setPivotY(centerFuImg.getHeight()/2);
                copyCenterFuImg.setVisibility(View.GONE);
            }

            @Override
            public void onAnimationRepeat(Animation animation) {

            }
        });
        AnimationPacket centerFuPacket3 = new AnimationPacket(centerFuImg,centerFuTranslateAnimationSet3,duration,false,"move2_center_fu");
        AnimationPacket copyCenterFuPacket3 = new AnimationPacket(copyCenterFuImg,copyCenterFuTranslateAnimationSet3,duration,false,"move2_center_fu");
        animationList.add(centerFuPacket3);
        animationList.add(copyCenterFuPacket3);
        animationList.add(delayPacket);
        animationList.add(delayPacket);




        RotateAnimation rotateCenterFuImgAnimation2 = new RotateAnimation(0, 7200, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
        rotateCenterFuImgAnimation2.setDuration(duration*4);

        rotateCenterFuImgAnimation2.setInterpolator(activity, android.R.anim.linear_interpolator);
        AnimationSet rotateCenterFuImgAnimationSet2 = new AnimationSet(true);
        rotateCenterFuImgAnimationSet2.addAnimation(rotateCenterFuImgAnimation);
        rotateCenterFuImgAnimationSet2.setDuration(duration*4);
        rotateCenterFuImgAnimationSet2.setFillAfter(true);
        rotateCenterFuImgAnimationSet2.setRepeatMode(Animation.REVERSE);

        RotateAnimation rotateCopyCenterFuImgAnimation2 = new RotateAnimation(0, 7200, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
        rotateCopyCenterFuImgAnimation2.setDuration(duration*4);

        rotateCopyCenterFuImgAnimation2.setInterpolator(activity, android.R.anim.linear_interpolator);
        AnimationSet rotateCopyCenterFuImgAnimationSet2 = new AnimationSet(true);
        rotateCopyCenterFuImgAnimationSet2.addAnimation(rotateCenterFuImgAnimation);
        rotateCopyCenterFuImgAnimationSet2.setDuration(duration*4);
        rotateCopyCenterFuImgAnimationSet2.setFillAfter(true);
        rotateCopyCenterFuImgAnimationSet2.setRepeatMode(Animation.REVERSE);

        rotateCenterFuImgAnimationSet2.setAnimationListener(new Animation.AnimationListener() {
            @Override
            public void onAnimationStart(Animation animation) {

            }

            @Override
            public void onAnimationEnd(Animation animation) {
                centerFuImg.clearAnimation();
                centerFuImg.setVisibility(View.GONE);

            }

            @Override
            public void onAnimationRepeat(Animation animation) {

            }
        });

        rotateCopyCenterFuImgAnimationSet2.setAnimationListener(new Animation.AnimationListener() {
            @Override
            public void onAnimationStart(Animation animation) {

            }

            @Override
            public void onAnimationEnd(Animation animation) {
                copyCenterFuImg.clearAnimation();
                copyCenterFuImg.setVisibility(View.GONE);

            }

            @Override
            public void onAnimationRepeat(Animation animation) {

            }
        });
        AnimationPacket rotateCenterFuPacket2 = new AnimationPacket(centerFuImg,rotateCenterFuImgAnimationSet2,duration*4,false,"rotate2_center_fu");
        AnimationPacket rotateCopyCenterFuPacket2 = new AnimationPacket(copyCenterFuImg,rotateCopyCenterFuImgAnimationSet2,duration*4,false,"rotate2_copy_center_fu");



        animationList.add(rotateCenterFuPacket2);
        animationList.add(rotateCopyCenterFuPacket2);

        animationList.add(delayPacket);
        animationList.add(delayPacket);
        animationList.add(delayPacket);
        animationList.add(delayPacket);




    }
    private ImageView copyImageView(ImageView srcImageView,boolean isStartAnimation,int x,int y){
        ImageView copyImg = new ImageView(activity);
//        copyImg.setVisibility(View.GONE);
//        copyImg.layout(srcImageView.getLeft(),srcImageView.getTop(),srcImageView.getRight(),srcImageView.getBottom());
        copyImg.setX(x);
        copyImg.setY(y);
        copyImg.setMaxWidth(srcImageView.getMaxWidth());
        copyImg.setMaxHeight(srcImageView.getMaxHeight());
        copyImg.setAdjustViewBounds(true);
        copyImg.setImageDrawable(srcImageView.getDrawable());
        if(isStartAnimation){
            AnimationDrawable animationDrawable = (AnimationDrawable)srcImageView.getDrawable();
            animationDrawable.start();
        }
        return copyImg;
    }
    //播放动画
    private void playAnimation(){
        //开启动画播放线程
        if(animationThread == null){
            animationThread = new Thread(new Runnable() {
                @Override
                public void run() {
                    while(!animationThread.isInterrupted()){
                        try{
                            if(currentIndex >=animationList.size() ){
                                Thread.sleep(200);
                                continue;
                            }
                            AnimationPacket packet = animationList.get(currentIndex);


                            currentIndex++;
                            if(packet.getImageView() != null){
                                Message msg = mAnimationHandler.obtainMessage(STATE_PLAY_ANIMATION,packet);
                                mAnimationHandler.sendMessage(msg);
                            }
                            if(packet.isBlock()){
                                Thread.sleep(packet.getDuration());
                            }


                        }catch (Exception e){
                            e.printStackTrace();
                            break;
                        }
                    }


                }
            });
            animationThread.start();
//            new Thread(new Runnable() {
//                @Override
//                public void run() {
//                    while (true){
//                        try {
//                            Thread.sleep(100);
//                            mAnimationHandler.sendEmptyMessage(STATE_REFRESH_TIME);
//                        } catch (InterruptedException e) {
//                            e.printStackTrace();
//                        }
//                    }
//                }
//            }).start();
        }
        currentIndex = 0;

    }
    @Override
    public void onClick(View v) {
        if("startImageView".equals(v.getTag().toString())){
            startImageView.setVisibility(View.GONE);
            playAnimation();
            startTime = System.currentTimeMillis();
            Toast.makeText(activity,"开始播放",Toast.LENGTH_SHORT).show();
            activity.getmMusicService().playMusic();
        }else if("restartImageView".equals(v.getTag().toString())){
            resetAnimation();
            activity.getmMusicService().stopMusic();
            startTime = System.currentTimeMillis();
        }else {

        }



    }

    private void resetAnimation(){
        int oldSize = animationList.size();
        if(animationList.size() >0){
            for(AnimationPacket packet : animationList){
                if(packet.getImageView() != null){
                    packet.getImageView().clearAnimation();
                    packet.getImageView().setVisibility(View.GONE);
                }

            }
            animationList.clear();
        }
        absoluteLayout.removeAllViews();
        absoluteLayout.addView(startImageView);
        absoluteLayout.addView(transparentImg);
        startImageView.setVisibility(View.VISIBLE);
        transparentImg.setVisibility(View.VISIBLE);
        currentIndex = oldSize;
        addAnimations();
        Toast.makeText(activity,"重置播放",Toast.LENGTH_SHORT).show();
    }

}
